﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;
namespace HFWebApp.instruments
{
    public partial class SearchInstrumentsList : BagePages
    {
        public string ClassTitle = "";
        public string PageStr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int PageSize = 16;
                int PageNumber = 1;
                if (this.GetQuery("Page") != "")
                {
                    PageNumber = int.Parse(this.GetQuery("Page"));
                }
                string strWhere = "";
                int total = 0;

                #region 条件搜索
                if (this.GetQuery("typeid") != "") {
                    int typeid = int.Parse(this.GetQuery("typeid"));
                    strWhere = "TypeID = " + typeid.ToString();
                    ClassTitle = InstrumentsController.getController().getInstrumentsFileTypeModel(typeid).TypeName;
                }

                #region 关键字搜索
                if (this.GetQuery("keyword") != "")
                {
                    string KeyWord = this.GetQuery("keyword");
                    string SearchType = this.GetQuery("searchType");
                    string SearchField = "";
                    
                    if (SearchType == "0")
                    {
                        SearchField = "Title";
                    }
                    else {
                        SearchField = "Content";
                    }

                    if (strWhere == "")
                    {
                        strWhere = SearchField + " like '%" + KeyWord + "%'";
                    }
                    else {
                        strWhere = strWhere + " and " + SearchField + " like '%" + KeyWord + "%'";
                    }

                    ClassTitle = "多条件搜索";
                }
                #endregion

                #region 分类搜索
                if (this.GetQuery("bclassid") != "")
                {
                    ClassTitle = "多条件搜索";
                    int bclassid = int.Parse(this.GetQuery("bclassid"));
                    if (bclassid != 0)
                    {
                        if (strWhere == "")
                        {
                            strWhere = "ClassID=" + bclassid.ToString();
                        }
                        else
                        {
                            strWhere = strWhere + " and ClassID=" + bclassid.ToString();
                        }
                    }
                }

                if(this.GetQuery("sclassid") != "")
                {
                    ClassTitle = "多条件搜索";
                    int sbclassid = int.Parse(this.GetQuery("sclassid"));
                    if (sbclassid != 0)
                    {
                        if (strWhere == "")
                        {
                            strWhere = "SmallClassID=" + sbclassid.ToString();
                        }
                        else
                        {
                            strWhere = strWhere + " and SmallClassID=" + sbclassid.ToString();
                        }
                    }
                }
                #endregion

                #endregion

                Repeater1.DataSource = InstrumentsController.getController().getInstrumentsList(PageSize ,PageNumber ,strWhere ,out total);
                Repeater1.DataBind();
                PageStr = LLL.Pager.TrunPageHtmlCode_Web(PageSize, PageNumber, total, "");
            }
        }
    }
}